# encoding: utf-8
# 项目名称： 常用设计模式
# @File  : 004-工厂方法模式.py
# @Author: sun hao
# @Desc : 
# @Date  :   14:14 2024/10/29

from abc import ABCMeta, abstractmethod


class Payment(metaclass=ABCMeta):
    """
    抽象支付类，定义了支付接口。
    """

    @abstractmethod
    def pay(self, money):
        pass


class Alipay(Payment):
    """
    支付宝支付类。
    """

    def __init__(self, use_huabei=False):
        self.use_huabei = use_huabei

    def pay(self, money):
        print("支付宝")
        if self.use_huabei:
            print(f"花呗支付{money}元")
        else:
            print(f"余额支付{money}元")


class WeChatPay(Payment):
    """
    微信支付类。
    """

    def pay(self, money):
        print("微信")
        print(f"支付{money}元")


class BankPay(Payment):
    """
    银行卡支付
    """

    def pay(self, money):
        print("银行卡")
        print(f"支付{money}元")


class PaymentFactory(metaclass=ABCMeta):
    @abstractmethod
    def create_payment(self):
        pass


class AlipayFactory(PaymentFactory):
    def create_payment(self):
        return Alipay()


class HuabeiAliapyFactory(PaymentFactory):
    def create_payment(self):
        return Alipay(use_huabei=True)


class WeChatPayFactory(PaymentFactory):
    def create_payment(self):
        return WeChatPay()


class BankPayFactory(PaymentFactory):
    def create_payment(self):
        return BankPay()


pf = WeChatPayFactory()
p = pf.create_payment()
p.pay(1014)
